<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js数组之逻辑</title>
</head>
<body>
  <ul>
    <li>可利用every()判断数组每一项是否都满足指定的条件，如都满足返回true,否则返回false</li>
    <li>可利用some()判断数组某一项是否都满足指定的条件，如满足返回true,否则返回false</li>
    <li>every()必须每一项都判断满足条件，some()只需要判断某一项满足条件则忽略其他项</li>
  </ul>
  <input type="text" name="keyword">
  <span name="msg"></span>
  <script>
    const blogs = [
      { url: 'https://github.com/miracle-git/vue', title: 'Vue学习' },
      { url: 'https://github.com/miracle-git/react', title: 'React学习' },
      { url: 'https://github.com/miracle-git/angular', title: 'Angular学习' }
    ]
    console.log(blogs.every(item => item.title.includes('学习')))  // true
    const keywords = ['js', 'es', 'ts']
    document.querySelector('[name="keyword"]').addEventListener('keyup', function () {
      const res = keywords.some(item => this.value.trim().indexOf(item) !== -1)
      document.querySelector('[name="msg"]').innerHTML = res ? '' : `关键字必须包含${keywords.join(',')}!`
    })
  </script>
</body>
</html>